package com.baige.api.app.controller;

import com.baige.api.app.sdk.request.*;
import com.baige.api.app.sdk.response.*;
import com.baige.common.core.BaseResponse;
import com.baige.common.core.MsgResponse;
import com.baige.common.core.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * 订单接口
 * @author wulg
 * @date 2018/12/13.
 */
@Api(value = "GoodsOrderController", description = "订单接口", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
@RestController
@RequestMapping("/api/rest/order")
public class GoodsOrderController
{

    private static final Logger logger = LoggerFactory.getLogger(GoodsOrderController.class);

    /**
     * 确认订单
     *
     * @param requestParams 请求参数
     * @param bindingResult 参数校验
     * @return Result<GoodsOrderConfirmResponse>
     */
    @PostMapping(value = "/v1/confirm", produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "确认订单", notes = "确认订单", httpMethod = "POST", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public Result<GoodsOrderConfirmResponse> confirmOrder(@RequestBody @Valid GoodsOrderConfirmRequest requestParams, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            logger.error("确认订单参数传递错误,message:{}", bindingResult.getFieldErrors().get(0).getDefaultMessage());
            return BaseResponse.newErrorParamReturnObject(bindingResult.getFieldErrors().get(0).getDefaultMessage());
        }
        return null;
    }

    /**
     * 用户下单
     *
     * @param requestParams 请求参数
     * @param bindingResult 参数校验
     * @return Result<OrderResponse>
     */
    @PostMapping(value = "/v1", produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "用户下单", notes = "用户下单", httpMethod = "POST", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public Result<OrderResponse> placeOrder(@RequestBody @Valid GoodsOrderAddRequest requestParams, BindingResult bindingResult)
    {
        if (bindingResult.hasErrors()) {
            logger.error("用户下单参数传递错误,message:{}", bindingResult.getFieldErrors().get(0).getDefaultMessage());
            return BaseResponse.newErrorParamReturnObject(bindingResult.getFieldErrors().get(0).getDefaultMessage());
        }
        return null;
    }

    /**
     * 订单归还详情
     *
     * @param orderId 订单id
     * @return Result<OrderGiveBackDetailResponse>
     */
    @GetMapping(value = "/v1/project/giveback/orderId/{orderId}", produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "订单归还详情", notes = "订单归还详情", httpMethod = "GET", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public Result<OrderGiveBackDetailResponse> getOrderGivebackDetail(@PathVariable("orderId") String orderId) {
        return null;
    }

    /**
     * 订单归还
     *
     * @param requestParams 请求参数
     * @param bindingResult 参数校验
     * @return Result<MsgResponse>
     */
    @PostMapping(value = "/v1/project/giveback", produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "订单归还", notes = "订单归还", httpMethod = "POST", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public Result<MsgResponse> orderGiveback(@RequestBody @Valid GiveBackRequest requestParams, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            logger.error("订单归还参数传递错误,message:{}", bindingResult.getFieldErrors().get(0).getDefaultMessage());
            return BaseResponse.newErrorParamReturnObject(bindingResult.getFieldErrors().get(0).getDefaultMessage());
        }
        return null;
    }


    /**
     * 订单取消
     *
     * @param requestParams 请求参数
     * @param bindingResult 参数校验
     * @return Result<MsgResponse>
     */
    @PutMapping(value = "/v1/cancel/orderId/{orderId}", produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "订单取消", notes = "订单取消", httpMethod = "PUT", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public Result<MsgResponse> orderCancel(@PathVariable("orderId") String orderId,@RequestBody GoodsOrderCancelRequest requestParams, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            logger.error("订单取消参数传递错误,message:{}", bindingResult.getFieldErrors().get(0).getDefaultMessage());
            return BaseResponse.newErrorParamReturnObject(bindingResult.getFieldErrors().get(0).getDefaultMessage());
        }
        return null;
    }


    /**
     * 查看物流
     *
     * @param logisticsCode 物流单号
     * @return Result<LogisticsResponse>
     */
    @GetMapping(value = "/v1/logistics/{logisticsCode}", produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "查看物流", notes = "查看物流", httpMethod = "GET", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public Result<LogisticsResponse> getLogisticsDetail(@PathVariable("logisticsCode") String logisticsCode) {
        return null;
    }

    /**
     * 订单支付宝支付
     *
     * @param orderId 订单id
     * @param requestParams 请求参数
     * @param bindingResult 参数校验
     * @return Result<AlipayOrderResponse>
     */
    @PostMapping(value = "/v1/{orderId}/alipay", produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "订单支付宝支付", notes = "订单支付宝支付", httpMethod = "POST", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public Result<AlipayOrderResponse> alipayOrder(@PathVariable("orderId") String orderId, @RequestBody AlipayOrderRequest requestParams, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            logger.error("订单支付宝支付参数传递错误,message:{}", bindingResult.getFieldErrors().get(0).getDefaultMessage());
            return BaseResponse.newErrorParamReturnObject(bindingResult.getFieldErrors().get(0).getDefaultMessage());
        }
        return null;
    }

    /**
     * 支付成功回调
     *
     * @param map 回调参数
     * @return String
     */
    @RequestMapping(value = "/v1/aliPay/notification", method = {RequestMethod.POST}, produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "支付成功回调", notes = "支付成功回调", httpMethod = "POST", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public String alipayOrderResultNotify(@RequestParam Map<String, String> map)
    {
        return null;
    }

    /**
     * 订单列表
     *
     * @param userId 用户id
     * @param requestParams 请求参数
     * @param bindingResult 参数校验
     * @return Result<List<OrderResponse>>
     */
    @GetMapping(value = "/v1/user/{userId}", produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "订单列表", notes = "订单列表", httpMethod = "GET", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public Result<List<OrderResponse>> getUserOrderListByUserId(@PathVariable("userId") String userId, @ModelAttribute("orderListRequest") @Valid OrderListRequest requestParams, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            logger.error("订单列表参数传递错误,message:{}", bindingResult.getFieldErrors().get(0).getDefaultMessage());
            return BaseResponse.newErrorParamReturnObject(bindingResult.getFieldErrors().get(0).getDefaultMessage());
        }
        return null;
    }


    /**
     * 订单详情
     *
     * @param orderId 订单id
     * @return Result<OrderDetailResponse>
     */
    @GetMapping(value = "/v/{orderId}", produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "订单详情", notes = "订单详情", httpMethod = "GET", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public Result<OrderDetailResponse> getOrderDetailByOrderId(@PathVariable("orderId") String orderId) {
        return null;
    }


    /**
     * 微信支付订单
     *
     * @param orderId 用户id
     * @param requestParams 请求参数
     * @param bindingResult 参数校验
     * @return Result<OrderWeChatPayResponse>
     */
    @PostMapping(value = "v1/orderId/{orderId}/weChat",  produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "微信支付订单", notes = "微信支付订单", httpMethod = "POST", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public Result<OrderWeChatPayResponse> wechatPayOrder(@RequestBody @Valid OrderWeChatPayRequest requestParams, BindingResult bindingResult, @PathVariable("orderId") String orderId) {
        if (bindingResult.hasErrors()) {
            logger.error("微信支付订单参数传递错误,message:{}", bindingResult.getFieldErrors().get(0).getDefaultMessage());
            return BaseResponse.newErrorParamReturnObject(bindingResult.getFieldErrors().get(0).getDefaultMessage());
        }
        return null;
    }

    /**
     * 微信支付通知
     *
     * @param requestParams 通知参数对象
     * @return OrderWeChatPayNotifyResponse
     */
    @RequestMapping(value = "/v1/weChat/notification", method = RequestMethod.POST, consumes = {"text/xml;charset=UTF-8"}, produces = {"application/xml;charset=UTF-8"})
    @ApiOperation(value = "微信支付通知", notes = "微信支付通知", httpMethod = "POST", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public OrderWeChatPayNotifyResponse weChatPayNotify(@RequestBody OrderWeChatPaymentNotifyRequest requestParams) {
        return null;
    }


    /**
     * 去支付
     *
     * @param orderId 订单id
     * @return OrderBaseInfoDto
     */
    @GetMapping(value = "/v1/{orderId}/pay", produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "去支付", notes = "去支付", httpMethod = "GET", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public Result<OrderResponse> orderToPay(@PathVariable("orderId") String orderId) {
        return null;
    }

    /**
     * 获取订单支付状态
     *
     * @param orderId 订单id
     * @return OrderPayResponse
     */
    @GetMapping(value = "/v1/{orderId}/pay/status", produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "获取订单支付状态", notes = "获取订单支付状态", httpMethod = "GET", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public Result<OrderDetailResponse> getOrderPayStatus(@PathVariable("orderId") String orderId) {
        return null;
    }

    /**
     * 获取最近一条未支付订单
     *
     * @param userId 用户id
     * @return Result<OrderResponse>
     */
    @GetMapping(value = "/v1/order/getUnPayOrderByUserId/{userId}", produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "获取最近一条未支付订单", notes = "获取最近一条未支付订单", httpMethod = "GET", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public Result<OrderResponse> getUnPayOrderByUserId(@PathVariable("userId") String userId) {
        return null;
    }

    /**
     * 删除订单
     *
     * @param orderId 订单id
     * @return Result<MsgResponse>
     */
    @DeleteMapping(value = "/v1/{orderId}", produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "删除订单", notes = "删除订单", httpMethod = "DELETE", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public Result<MsgResponse> removeOrder(@PathVariable("orderId") String orderId) {
        return null;
    }

    /**
     * 订单账户支付
     *
     * @param orderId 订单id
     * @return Result<MsgResponse>
     */
    @PostMapping(value = "/v1/account/pay/{orderId}", produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "订单账户支付", notes = "订单账户支付", httpMethod = "POST", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public Result<MsgResponse> accountPayOrder(@PathVariable("orderId") String orderId) {
        return null;
    }
}
